{include file="Public:header" /}
    
    <style>
		.icheck_float_left{
			float:left;
		}
	</style>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>分配权限</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="">
                            <a href="#" class="btn btn-primary dim" aria-controls="messages" role="button" data-toggle="modal" data-target="#myModal"><span class="fa fa-plus"></span> 为<span style="color:red">{$group_data['title']}</span>分配权限</a>
                        </div>
                        <br/>
                        <div class="table-responsive">
					  
					     	 
  <form action="__URL__/ruleGroup" method="post">
	<input type="hidden" name="id" value="{$group_data['id']}">
	<div class="table-responsive">
	<table class="table table-bordered">
		{foreach name="rule_data" item="v"}
			{empty name="v['_data']"}
				<tr class="b-group">
					<th width="10%">
					<div class="i-check icheck_float_left one_lever">
						<label>
							{$v['title']}
							<input type="checkbox" name="rule_ids[]" value="{$v['id']}" {if condition="in_array($v['id'],$group_data['rules'])"}	checked="checked"{/if} onclick="checkAll(this)" >
						</label>
					</div>
					</th>
					<td></td>
				</tr>
			{else /}
				<tr class="b-group">
					<th width="10%">
					<div class="i-check icheck_float_left one_lever" >
						<label>
							{$v['title']} <input type="checkbox" name="rule_ids[]" value="{$v['id']}" {if condition="in_array($v['id'],$group_data['rules'])"}	checked="checked"{/if} onclick="checkAll(this)" >
						</label>
					</div>
					</th>
					<td class="b-child">
						{foreach name="v['_data']" item="n"}
							<table class="table table-bordered">
								<tr class="b-group">
									<th width="15%">
									<div class="i-check icheck_float_left two_lever">
										<label>
											{$n['title']} <input type="checkbox" name="rule_ids[]" value="{$n['id']}" {if condition="in_array($n['id'],$group_data['rules'])"}	checked="checked"{/if} onclick="checkAll(this)">
										</label>
									</div>
									</th>
									<td>
										{notempty name="n['_data']"}
											{volist name="n['_data']" id="c"}
											<div class="i-check icheck_float_left">
												<label>
													&emsp;{$c['title']} <input type="checkbox" name="rule_ids[]" value="{$c['id']}" {if condition="in_array($c['id'],$group_data['rules'])"}	checked="checked"{/if} >
												</label>
											</div>
											{/volist}							
										{/notempty}
									</td>
								</tr>
							</table>
						{/foreach}
					</td>
				</tr>
			{/empty}
		{/foreach}
		<tr>
			<th></th>
			<td>
				<input class="btn btn-primary" type="submit" value="提交">
			</td>
		</tr>
	</table>
	</div>
</form>
     					 </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

{include file="Public:footer" /}

<script>
$(document).ready(function() {
    /**
     * 下面是进行插件初始化
     * 你只需传入相应的键值对
     * */
    $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {/*输入框不同状态，显示图片的样式*/
            	  valid: 'glyphicon glyphicon-ok',
                  invalid: 'glyphicon glyphicon-remove',
                  validating: 'glyphicon glyphicon-refresh'
            },
            fields: {/*验证*/
            	title: {/*键名username和input name值对应*/
                    message: '用户组名验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '用户组名不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 4,
                            max: 30,
                            message: '用户组名长度必须在4到30之间'
                        }/*最后一个没有逗号*/
                    }
                }
            }
            // 还有一个比较常用的就是submitHandler属性，它对应着提交按钮的事件方法。
            // submitHandler: function (validator, form, submitButton) {
                //alert("submit");
               /*  var menu_name = $("input[name='menu_name']").val();
                var link = $("input[name='link']").val();
                var ico = $("input[name='ico']").val();
                $.ajax({
                    url : '__URL__/addMenu',
                    type : 'get',
                    data : {'menu_name' : menu_name, 'link' : link, 'ico':ico},
                    dataType : 'json',
                    success : function(data){
                      alert(data.message);
                    }
                }); */
           // }
        });
});

//选择按钮
$(".one_lever .iCheck-helper").click(function(){
		var getClass = $(this).parents("div").attr("class");
		if(getClass == 'icheckbox_square-green hover checked'){
			$(this).parents('.b-group').eq(0).find(".b-child").find(".i-check").iCheck('check');
		}else{
			$(this).parents('.b-group').eq(0).find(".b-child").find(".i-check").iCheck('uncheck');
		}
});

$(".two_lever .iCheck-helper").click(function(){
	var getClass = $(this).parent("div").attr("class");
	if(getClass == 'icheckbox_square-green hover checked'){
		$(this).parent('div').parent('label').parent('div').parent('th').siblings('td').find(".i-check").iCheck('check');
	}else{
		$(this).parent('div').parent('label').parent('div').parent('th').siblings('td').find(".i-check").iCheck('uncheck');
	} 
});

</script>
</body>
</html>
